home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 29
/
Volume 29 - JOGO DISK .iso
/
Games
/
jungle_adventure.swf
/
scripts
/
__Packages
/
FlyingObject.as
< prev
next >
Wrap
Text File
|
2006-11-29
|
7KB
|
255 lines
class FlyingObject extends SSObject
{
var classID = SSGlobal.CLSID_MOBILEOBJECT;
var collisionMask = SSGlobal.CLSID_MAINCHAR;
var healthValue = -0.2;
var assetID = "FlyingObject";
var immobilized = 0;
var travelSpeed = 400;
var stage = 0;
var dirX = 0;
var dirY = 0;
var soundOn = false;
var maxSpeed = 100;
var pLast = 0;
var zDir = 0;
var waitTime = 1;
var waitSyncTime = 8;
var waitOffset = 0;
var offsetX = 0;
var offsetY = 0;
var editor_isItem = true;
var editor_name = "FlyingObject";
var editor_args_names = ["offsetX","offsetY","waitSyncTime"];
var editor_args_values = [FlyingObject.prototype.offsetX,FlyingObject.prototype.offsetY,FlyingObject.prototype.waitSyncTime];
var editor_args_types = ["number","number","number"];
var editor_args_options = [[-1000,1000,25],[-1000,1000,25],[1,10,0.5]];
var editor_args_descriptions = ["","",""];
var editor_args_mode = [0,0,0];
var editor_args_component = ["NumericStepper","NumericStepper","NumericStepper"];
function FlyingObject(offsetX, offsetY)
{
super();
if(offsetX != null)
{
this.offsetX = offsetX;
}
if(offsetY != null)
{
this.offsetY = offsetY;
}
}
function onAddToWorld()
{
this.originX = this.x;
this.originY = this.y;
this.nextDest(this.originX + this.offsetX,this.originY + this.offsetY);
}
function onAddToScene()
{
this.getUpdates();
if(this.offsetX || this.offsetY)
{
this.update = this.update_motion;
}
else
{
delete this.update;
}
if(this.waitTime)
{
this.syncTime();
}
this.soundOn = false;
this.snd = new Sound(this.target);
this.snd.attachSound("jet");
}
function onRemoveDisplay()
{
this.soundOn = false;
this.snd.stop();
this.snd = null;
}
function onRemoveFromScene()
{
this.cancelUpdates();
if(this.immobilized)
{
this.immobilized = 0;
this.moveTo(this.originX,this.originY,0);
this.stage = 0;
}
}
function update(elapsed)
{
if(this.world.time > this.pLast + 0.1)
{
this.dropParticle("Smoke",this.x + 30,this.y,this.z,0,100,-10);
}
this.adjustSound();
}
function adjustSound()
{
var _loc2_ = this.world.viewport;
var _loc4_ = this.target._x - _loc2_.x - _loc2_.halfWidth;
var _loc5_ = this.target._y - _loc2_.y - _loc2_.halfHeight;
var _loc3_ = 1 - (_loc4_ * _loc4_ + _loc5_ * _loc5_) / 250000;
if(_loc3_ > 0)
{
if(!this.soundOn)
{
this.snd.start(0,1048575);
this.soundOn = true;
}
this.snd.setVolume(Math.floor(_loc3_ * 100));
this.snd.setPan(Math.round(_loc4_ / 500 * 100));
}
else if(this.soundOn)
{
this.snd.stop();
this.soundOn = false;
}
}
function syncTime()
{
this.waitTime = this.waitSyncTime - (this.world.time + this.waitOffset) % this.waitSyncTime;
}
function nextDest()
{
if(this.stage = !this.stage)
{
this.destX = this.originX + this.offsetX;
this.destY = this.originY + this.offsetY;
}
else
{
this.destX = this.originX;
this.destY = this.originY;
}
var _loc4_ = this.destX - this.x;
var _loc3_ = this.destY - this.y;
var _loc2_ = Math.sqrt(_loc4_ * _loc4_ + _loc3_ * _loc3_);
if(_loc2_ > 0.0001)
{
this.dirX = _loc4_ / _loc2_;
this.dirY = _loc3_ / _loc2_;
}
else
{
this.dirX = 0;
this.dirY = 0;
}
}
function update_motion(elapsed)
{
if(this.waitTime)
{
if((this.waitTime -= elapsed) <= 0)
{
this.waitTime = 0;
this.nextDest();
}
}
else
{
var _loc5_ = this.destX - this.x;
var _loc4_ = this.destY - this.y;
var _loc3_ = Math.sqrt(_loc5_ * _loc5_ + _loc4_ * _loc4_);
var _loc2_ = Math.sqrt(this.velocity.x * this.velocity.x + this.velocity.y * this.velocity.y);
if(_loc2_ < _loc3_)
{
if(_loc2_ < this.maxSpeed)
{
if((_loc2_ += this.maxSpeed * elapsed) < this.maxSpeed)
{
this.velocity.x = _loc2_ * this.dirX;
this.velocity.y = _loc2_ * this.dirY;
}
else
{
this.velocity.x = this.maxSpeed * this.dirX;
this.velocity.y = this.maxSpeed * this.dirY;
}
}
}
else if(_loc3_ > 10)
{
this.velocity.x = this.dirX * _loc3_;
this.velocity.y = this.dirY * _loc3_;
}
else
{
this.syncTime();
}
this.moveBy(this.velocity.x * elapsed,this.velocity.y * elapsed,0);
}
this.adjustSound();
if(this.world.time > this.pLast + 0.1)
{
this.dropParticle("Smoke",this.x + 30,this.y,this.z,0,100,-10);
}
}
function dropParticle(asset, x, y, z, vx, vy, vz)
{
var _loc2_ = new SSParticle(asset,1,new Vector(vx,vy,vz),180);
_loc2_.x = x;
_loc2_.y = y;
_loc2_.z = z;
this.world.addObject(_loc2_);
this.pLast = this.world.time;
}
function immobilize()
{
this.update = this.update_immobile;
this.velocity.y = 0;
GameSound.playSound("enemyhit");
this.zDir = !random(2) ? 150 : -150;
this.immobilized = 10;
}
function update_immobile(elapsed)
{
var _loc0_ = null;
var _loc5_ = this.target._rotation -= 480 * elapsed;
var _loc2_ = _loc5_ * 0.0174532925199433;
var _loc6_ = Math.cos(_loc2_);
var _loc4_ = Math.sin(_loc2_);
this.velocity.y += SSGlobal.GRAVITY * elapsed * 0.25;
this.moveBy(0,this.velocity.y * elapsed,this.zDir * elapsed);
this.snd.setVolume(Math.max((1 - Math.abs(this.z / 300)) * 100,0));
if(this.z < -300)
{
this.removeFromScene();
}
if(this.world.time > this.pLast + 0.1)
{
this.dropParticle("Smoke",this.x + 30 * _loc6_,this.y + 30 * _loc4_,this.z,0,100,-10);
}
}
function onCollision(obj)
{
if(this.immobilized || !this.inScene)
{
return undefined;
}
if((obj.classID & 4294901760) == SSGlobal.CLSID_MAINCHAR)
{
if(obj.classID == SSGlobal.CLSID_VEHICLE || obj.y < this.y - this.radius * 0.25)
{
this.immobilize();
obj.velocity.x *= 1.1;
obj.velocity.y *= -0.5;
}
else
{
obj.shiftHealth(this.healthValue,this);
}
}
}
function editor_onDisplay(target, external)
{
target.clear();
target.lineStyle(0,16776960);
target.lineTo(this.offsetX,this.offsetY);
}
}